package algorithm;

import java.util.Stack;

// 栈实现队列
public class StackMakeQueueTest {
    public static void main(String[] args) {
        StackMakeQueue queue = new StackMakeQueue();
        queue.add(1);
        queue.add(3);
        queue.add(4);
        while (!queue.isEmpty()) {
            System.out.print(queue.poll());
        }
    }
}


class StackMakeQueue{

    Stack<Integer> s1 = new Stack<>();
    Stack<Integer> s2 = new Stack<>();

    public void add(Integer data) {
        s1.push(data);
    }

    public Integer poll(){
        if (s2.isEmpty()) {
            // s2为空，从
            while (s1.size()>0) {
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int size(){
        return s1.size() + s2.size();
    }

    public boolean isEmpty(){
        return s1.isEmpty() && s2.isEmpty();
    }
}
